package com.hgxd.test.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;
import com.hgxd.result.Result;

import com.hgxd.test.service.IDictService;
import com.hgxd.entity.pojo.Dict;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 组织架构表 前端控制器
 * </p>
 *
 * @author fsd
 * @since 2023-10-19
 */
@Api(tags = "")
    @RestController
@RequestMapping("/dict")
    public class DictController {
@Resource(name = "DictServiceImpl")
private IDictService dictService;

/**
* 新增
*/
@PostMapping("/save")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result insert(@RequestBody Dict dict) {
        return Result.ok(dictService.save(dict));
        }

/**
* 修改
*/
@PostMapping("/update")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result update(@RequestBody Dict dict) {
        return Result.ok(dictService.updateById(dict));
        }

/**
* 根据id删除
*/
@PostMapping("/delete/{id}")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result delete(@PathVariable Integer id) {
        return Result.ok(dictService.removeById(id));
        }

/**
* 批量删除
*/
@PostMapping("/del/batch")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(dictService.removeByIds(ids));
        }

/**
* 查询全部
*/
@GetMapping("/getAll")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result findAll() {
        return Result.ok(dictService.list());
        }

/**
* 根据id查询一个
*/
@GetMapping("getById/{id}")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result findOne(@PathVariable Integer id){
        return Result.ok(dictService.getById(id));
        }

/**
* 分页模糊查询
*/
@GetMapping("/get/page")
@ApiOperation(value = "",notes = "")
@ApiImplicitParam(name = "" ,value = "")
public Result findPage(@RequestParam Integer pageNum,
@RequestParam Integer pageSize) {
        QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(dictService.page(new Page<>(pageNum, pageSize),queryWrapper));
        }
        }

